/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the GPL
 * version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.actions;

import org.digitalsoul.switchplugin.model.ISwitchFile;
import org.digitalsoul.switchplugin.model.SwitchFile;

public class FileSuffixAction extends Action {

    private final String suffix;

    public FileSuffixAction(String suffix) {
        this.suffix = suffix;
    }

    @Override
    public ISwitchFile applyAction(ISwitchFile file) {
        SwitchFile newFile = new SwitchFile(file);
        String newName = newFile.getBaseName();
        if (!isInverse) {
            newName += suffix;
        }
        else {
            newName = newName.replaceAll(suffix + "$", "");
        }
        newFile.changeBaseName(newName);
        return newFile;
    }

    @Override
    public ActionType getType() {
        return ActionType.SUFFIX_APPEND;
    }

    @Override
    public String toString() {
        return suffix;
    }

    @Override
    public boolean isInversable() {
        return true;
    }
}
